package arrayOps

import (
	"fmt"
	C "gitee.com/ljfirst/algo-go-sdk/common/constant"
)

/**
 * @author ljfirst
 * @version V1.0
 * @date 2023/7/16 00:33
 * @author-Email ljfirst@mail.ustc.edu.cn
 * @blogURL https://blog.csdn.net/ljfirst
 * @description
 **/
type FlightBookings struct {
}

func (m *FlightBookings) Method(bookingRecord [][]int, seatNum int) []int {
	if len(bookingRecord) == 0 {
		return nil
	}
	tools := &DiffArray{}
	tools.BuildDiffArray(make([]int, seatNum, seatNum))
	for i := 0; i < len(bookingRecord); i++ {
		if bookingRecord[i][0] > seatNum || bookingRecord[i][1] > seatNum {
			fmt.Println("FlightBookings data error")
			return nil
		}
		indexI := bookingRecord[i][0] - 1 // attention : 它们分别从 1 到 n 进行编号,所以索引值需要减1
		indexJ := bookingRecord[i][1] - 1
		val := bookingRecord[i][2]
		tools.Increase(indexI, indexJ, val)
	}
	return tools.GetDiffArray()
}

func (m *FlightBookings) GetAttribute() *C.Attribute {
	return &C.Attribute{
		Tags: []string{C.DiffArray},
		Desc: &C.Desc{
			Name:        "FlightBookings",
			NameCn:      "",
			Description: "",
			ParamsDesc: map[string]string{
			},
			Example: map[int]string{
				1: "这里有n个航班，它们分别从 1 到 n 进行编号。有一份航班预订表bookings ，表中第i条预订记录bookings[i] = [firsti, lasti, seatsi]" +
					"意味着在从 firsti 到 lasti （包含 firsti 和 lasti ）的 每个航班 上预订了 seatsi个座位。" +
					"请你返回一个长度为 n 的数组answer，里面的元素是每个航班预定的座位总数。",
			},
		},
	}
}
